import { View } from "../../../../mvc/core/View";
import { PageTool } from "../../../../common/global/PageTool";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { PetIlluEventName } from "./PetIlluEventName";
import { PetManualConfig } from "../../../resource/PetManualConfig";
import { GComboBox } from "../../../../../com/mui/controls/GComboBox";
import { MailFriendItemCellRender } from "../../mail/MailFriendItemCellRender";
import { ResouceConst } from "../../../../component/gconst/ResouceConst";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { Language } from "../../../../../extend/language/Language";
import { DataProvider } from "../../../../../fl/data/DataProvider";
import { ObjCreate } from "../../common/ObjCreate";
import { Cache } from "../../../cache/Cache";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
import { TilePanel } from "../../equipment/TilePanel";
import { PetIlluListRenderer } from "./PetIlluListRenderer";
import { PageSelecter } from "../../common/pageSelect/PageSelecter";
import { PetManualInfo } from "./PetManualInfo";
import { DataEvent } from "../../../events/DataEvent";
import { PetConfig } from "../../../resource/PetConfig";
import { GTextFiled } from "../../../../../com/mui/controls/GTextFiled";
type int = number;
//class PetIlluPetListPanel
    
    export  class PetIlluPetListPanel extends View
    {
        constructor()
        {
            super();
            this._allManualArray = [];
            this._pageTool = new PageTool([], 2);
            this.init();
            Dispatcher.addEventListener(PetIlluEventName.SearchPetByType, this.onSearchPetByTypeHandler);
            return;
        }

        /* internal  */init(): void
        {
            this._allManualArray = PetManualConfig.instance.getManualList(0);
            this._manualArray = this._allManualArray;
            this._physicCombo = new GComboBox();
            this._physicCombo.styleName = "GComboboxStyle";
            this._physicCombo.drawNow();
            this._physicCombo.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            this._physicCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._physicCombo.dropdown.rowCount = 10;
            this._physicCombo.dropdown.rowHeight = 25;
            this._physicCombo.dropdown.drawNow();
            this._physicCombo.textField.setStyle("textFormat", GlobalStyle.textFormat1);
            this._physicCombo.prompt = Language.getString(54081);
            this._physicCombo.setSize(100, 25);
            this._physicCombo.move(15, 5);
            this._physicCombo.dataProvider = new DataProvider(PetManualConfig.instance.getManualList(0, 0));
            this._physicCombo.addEventListener(flash.events.Event.CHANGE, this.onComboChangeHandler);
            this.addChild(this._physicCombo);
            this._magicCombo = new GComboBox();
            this._magicCombo.styleName = "GComboboxStyle";
            this._magicCombo.drawNow();
            this._magicCombo.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            this._magicCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._magicCombo.dropdown.rowCount = 10;
            this._magicCombo.dropdown.rowHeight = 25;
            this._magicCombo.dropdown.drawNow();
            this._magicCombo.textField.setStyle("textFormat", GlobalStyle.textFormat1);
            this._magicCombo.prompt = Language.getString(54082);
            this._magicCombo.setSize(100, 25);
            this._magicCombo.move(135, 5);
            this._magicCombo.dataProvider = new DataProvider(PetManualConfig.instance.getManualList(0, 1));
            this._magicCombo.addEventListener(flash.events.Event.CHANGE, this.onComboChangeHandler);
            this.addChild(this._magicCombo);
            this._habitusCombo = new GComboBox();
            this._habitusCombo.styleName = "GComboboxStyle";
            this._habitusCombo.drawNow();
            this._habitusCombo.dropdown.setStyle("cellRenderer", MailFriendItemCellRender);
            this._habitusCombo.dropdown.setStyle("skin", ResouceConst.getScaleBitmap(ImagesConst.WindowCenterB));
            this._habitusCombo.dropdown.rowCount = 10;
            this._habitusCombo.dropdown.rowHeight = 25;
            this._habitusCombo.dropdown.drawNow();
            this._habitusCombo.textField.setStyle("textFormat", GlobalStyle.textFormat1);
            this._habitusCombo.prompt = Language.getString(54083);
            this._habitusCombo.setSize(100, 25);
            this._habitusCombo.move(260, 5);
            this._habitusCombo.dataProvider = new DataProvider(PetManualConfig.instance.getManualList(0, 2));
            this._habitusCombo.addEventListener(flash.events.Event.CHANGE, this.onComboChangeHandler);
            this.addChild(this._habitusCombo);
            this._hadTxt = ObjCreate.createGTextField(Language.getString(54084) + Cache.instance.pet.collectedPets.length + "/" + this._allManualArray.length, 380, 10, 100, 20, this, GlobalStyle.textFormat6);
            this._hadTxt.toolTipData = HTMLUtil.addColor(Language.getString(54085), "#ffffff");
            this._listPanel = new TilePanel();
            this._listPanel.setStyle("cellRenderer", PetIlluListRenderer);
            this._listPanel.columnWidth = 490;
            this._listPanel.rowHeight = 225;
            this._listPanel.setSize(500, 460);
            this._listPanel.move(2, 40);
            this.addChild(this._listPanel);
            this._pageTool.array = this._allManualArray;
            this._pageBar = new PageSelecter();
            this._pageBar.mode = PageSelecter.CompleteMode;
            this._pageBar.move(200, 490);
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this._pageBar.addEventListener(flash.events.Event.CHANGE, this.onChangeHandler);
            this.addChild(this._pageBar);
            this.onChangeHandler(null);
            return;
        }

        public showToPetPage(arg1: int): void
        {
            var loc1=this.getManualPageIndex(arg1);
            this._pageBar.currentPage = loc1;
            this.onChangeHandler(null);
            return;
        }

        /* internal  */onChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=this._pageBar.currentPage;
            this._listPanel.dataProvider = new DataProvider(this._pageTool.getByPageNo(loc1));
            return;
        }

        /* internal  */onComboChangeHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=(arg1.target as GComboBox).selectedItem as PetManualInfo;
            var loc2=this.getManualPageIndex(loc1.id);
            this._pageBar.currentPage = loc2;
            this.onChangeHandler(null);
            return;
        }

        /* internal  */onSearchPetByTypeHandler(arg1: DataEvent): void
        {
            var loc1=arg1.data as int;
            if (loc1 != -1) 
            {
                this._manualArray = PetManualConfig.instance.getManualList(0, loc1);
            }
            else 
            {
                this._manualArray = PetManualConfig.instance.getManualList(0);
            }
            this._pageTool.array = this._manualArray;
            this._pageBar.maxPage = this._pageTool.pagesCount;
            this._pageBar.currentPage = 1;
            this.onChangeHandler(null);
            this.enableCombo(loc1);
            return;
        }

        /* internal  */enableCombo(arg1: int): void
        {
            if (arg1 != -1) 
            {
                if (arg1 != 0) 
                {
                    if (arg1 != 1) 
                    {
                        if (arg1 == 2) 
                        {
                            this._physicCombo.enabled = false;
                            this._magicCombo.enabled = false;
                            this._habitusCombo.enabled = true;
                        }
                    }
                    else 
                    {
                        this._physicCombo.enabled = false;
                        this._magicCombo.enabled = true;
                        this._habitusCombo.enabled = false;
                    }
                }
                else 
                {
                    this._physicCombo.enabled = true;
                    this._magicCombo.enabled = false;
                    this._habitusCombo.enabled = false;
                }
            }
            else 
            {
                this._physicCombo.enabled = true;
                this._magicCombo.enabled = true;
                this._habitusCombo.enabled = true;
            }
            this._physicCombo.selectedIndex = -1;
            this._magicCombo.selectedIndex = -1;
            this._habitusCombo.selectedIndex = -1;
            return;
        }

        /* internal  */getManualPageIndex(arg1: int): int
        {
            var loc1=0;
            var loc2=0;
            var loc3=null;
            var loc4=PetConfig.instance.getInfoByCode(arg1);
            var loc5=0;
            while (loc5 < this._manualArray.length) 
            {
                if ((loc3 = this._manualArray[loc5]).id == arg1 || loc4 && loc3.propertyOne.toString() == loc4.modelId) 
                {
                    loc2 = loc5 + 1;
                    break;
                }
                ++loc5;
            }
            loc1 = loc2 % 2 != 0 ? int(loc2) / 2 + 1 : loc2 / 2;
            return loc1;
        }

        /* internal */ /* var */_physicCombo: GComboBox;

        /* internal */ /* var */_magicCombo: GComboBox;

        /* internal */ /* var */_habitusCombo: GComboBox;

        /* internal */ /* var */_hadTxt: GTextFiled;

        /* internal */ /* var */_listPanel: TilePanel;

        /* internal */ /* var */_pageBar: PageSelecter;

        /* internal */ /* var */_listDp: DataProvider;

        /* internal */ /* var */_allManualArray: Array<any>;

        /* internal */ /* var */_manualArray: Array<any>;

        /* internal */ /* var */_pageTool: PageTool;
    }
